#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int T;
    cin >> T;
    while (T--)
    {
        int n, k;
        cin >> n >> k;
        string str;
        cin >> str;
        int sum = 0;
        int p = 0;
        for (auto s : str)
        {
            if (s == 'W')
            {
                p++;
                if (p >= 3)
                {
                    sum += k;
                }
                else
                {
                    sum++;
                }
            }
            else
            {
                p = 0;
                sum--;
            }
        }
        cout << sum << endl;
    }
    return 0;
}

class Solution {
public:
    int maxLength(vector<int>& arr) {
        // write code here
        vector<int> board(1e5 + 10);
        int left = 0;
        int right = 0;
        int n = arr.size();
        int my_length = 0;
        while (right < n)
        {
            board[arr[right]]++;
            while (board[arr[right]] > 1)
            {
                board[arr[left++]]--;
            }
            my_length = max(my_length, right - left + 1);
            right++;
        }
        return my_length;
    }
};

int main() {
    int n;
    string str;
    cin >> n >> str;
    int arr[26];
    for (auto s : str)
    {
        arr[s - 'a']++;
    }
    priority_queue<pair<char, int>> q;
    for (int i = 0; i < n; i++)
    {
        if (arr[i])
        {
            q.push(pair<char, int>(i + 'a', arr[i]));
        }
    }
    string ret;
    char prev = 0;
    while (q.size())
    {
        auto [x, y] = q.top();
        q.pop();
        if (x == prev)
        {
            if (q.size() == 0)
            {
                cout << "no" << endl;
                return 0;
            }
            else
            {
                auto [a, s] = q.top();
                q.pop();
                ret += a;
                ret += x;
                s--;
                y--;
                if (s != 0)
                {
                    q.push({ a,s });
                }
                q.push({ x,y });
                prev = x;
            }
        }
        else
        {
            ret += x;
            y--;
            if (y)
            {
                q.push({ x,y });
            }
            prev = x;
        }
    }
    cout << "yes" << endl;
    cout << ret << endl;
    return 0;
}


const int N = 1e5 + 10;
char str[N];
char ret[N];
int cnt[26] = { 0 };
int n;

int main() {
    cin >> n >> str;
    char maxC = 0;
    int maxCount = 0;
    for (int i = 0; i < n; i++)
    {
        cnt[str[i] - 'a']++;
        if (cnt[str[i] - 'a'] > maxCount)
        {
            maxC = str[i];
            maxCount = cnt[str[i] - 'a'];
        }
    }
    if (maxCount > (n + 1) / 2)
    {
        cout << "no" << endl;
    }
    else
    {
        cout << "yes" << endl;
        int i = 0;
        while (maxCount--)
        {
            ret[i] = maxC;
            i += 2;
        }
        for (int j = 0; j < 26; j++)
        {
            if (cnt[j] && (j + 'a' != maxC))
            {
                while (cnt[j]--)
                {
                    if (i >= n)
                    {
                        i = 1;
                    }
                    ret[i] = j + 'a';
                    i += 2;
                }
            }
        }
        for (int j = 0; j < n; j++)
        {
            cout << ret[j];
        }
        cout << endl;
    }
    return 0;
}

int main() {
    string str1;
    string str2;
    cin >> str1 >> str2;
    int ar1[26] = { 0 };
    int ar2[26] = { 0 };
    for (auto s : str1)
    {
        ar1[s - 'A']++;
    }
    for (auto s : str2)
    {
        ar2[s - 'A']++;
    }
    for (int i = 0; i < 26; i++)
    {
        if (ar1[i] < ar2[i])
        {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}